package com.imooc.bilibili.controller;

import com.imooc.bilibili.entity.UserFollowingGroup;
import com.imooc.bilibili.entity.UserFollowingInfo;
import com.imooc.bilibili.request.UserFollowRequest;
import com.imooc.bilibili.result.Result;
import com.imooc.bilibili.service.UserFollowService;
import com.imooc.bilibili.support.UserSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user_follow_service")
public class UserFollowController {

    @Autowired
    private UserFollowService userFollowService;

    @Autowired
    private UserSupport userSupport;

    @PostMapping("/insert-user-follow")
    public Result<String> insertUserFollow(UserFollowRequest request) {
        userFollowService.insertUserFollowingsService(request);
        return Result.success();
    }

    @GetMapping("/get-user-followings")
    public Result<List<UserFollowingGroup>> getUserFollowingInfos() {
        //获取用户id
        Map<String, Long> currnetMap = userSupport.getCurrnetUserId();
        Long userId = currnetMap.get("userId");
        List<UserFollowingGroup> userFollowInfosService = userFollowService.getUserFollowInfosService(userId);
        return new Result<>(userFollowInfosService);
    }

    @GetMapping("/get-user-fans")
    public Result<List<UserFollowingInfo>> getUserFansInfo() {
        //获取用户id
        Map<String, Long> currnetMap = userSupport.getCurrnetUserId();
        Long userId = currnetMap.get("userId");
        List<UserFollowingInfo> userFansService = userFollowService.getUserFansService(userId);
        return new Result<>(userFansService);
    }

    @PostMapping("/insert-user-following-groups")
    public Result<Long> insertUserFollowingGroups(@RequestBody UserFollowRequest request) {
        Map<String, Long> currnetUserId = userSupport.getCurrnetUserId();
        Long userId = currnetUserId.get("userId");
        request.setUserId(userId);
        Long groupId = userFollowService.insertUserFollowingGroupService(request);
        return new Result<>(groupId);
    }

    @GetMapping("/get-user-following-groups")
    public Result<List<UserFollowingGroup>> getUserFollowingGroups() {
        Map<String, Long> currnetUserId = userSupport.getCurrnetUserId();
        Long userId = currnetUserId.get("userId");
        List<UserFollowingGroup> groupList = userFollowService.getUserFollowingGroupService(userId);
        return new Result<>(groupList);
    }

}
